package com.ymatou.query.seller.trading.api.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.seller.trading.api.parameter.GetAppSellerOrdersResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

/**
 * @date 2016-06-13
 * @desc 获取商家订单列表.开放: 多商品 and M端商品 and 主单号
 * 
 * @author songyefeng
 *
 */
public class GetAppSellerOrdersCall extends YmatouBaseCall {
	private static String opurl = "api/Seller/GetAppSellerOrders";

	public GetAppSellerOrdersCall() {
		super(EnvSetup.getSystemUrl("api_seller_order_query"), opurl, "POST",
				"JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("Code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("Msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public Object getData() {
		Object Data = null;
		try {
			Data = new JSONObject(getReturnData()).get("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	public GetAppSellerOrdersResponse getAppSellerOrdersResponse() {
		return (GetAppSellerOrdersResponse) FormatUtil.GSONToObject(getData()
				.toString(), GetAppSellerOrdersResponse.class);
	}

	/**
	 * 获取$.Data.Orders
	 * 
	 * @return
	 */
	public JSONArray getDataOrders() {
		JSONArray orders = null;
		try {
			orders = ((JSONObject) getData()).getJSONArray("Orders");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return orders;
	}

	/**
	 * 获取$.Data.LastOrderId
	 * 
	 * @return
	 */
	public Integer getDataLastOrderId() {
		Integer LastOrderId = null;
		try {
			LastOrderId = ((JSONObject) getData()).getInt("LastOrderId");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return LastOrderId;
	}

}
